package com.haitonghop.main;

import java.io.File;
import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
import com.androidquery.callback.BitmapAjaxCallback;
import com.androidquery.callback.ImageOptions;
import com.androidquery.util.AQUtility;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.BaseDialogListener;
import com.facebook.android.BaseRequestListener;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.LoginButton;
import com.facebook.android.SessionEvents;
import com.facebook.android.SessionEvents.AuthListener;
import com.facebook.android.SessionEvents.LogoutListener;
import com.facebook.android.SessionStore;
import com.facebook.android.Utility;
import com.haitonghop.R;
import com.haitonghop.controls.AdsViewControl;
import com.haitonghop.data.HaiBLModule;
import com.haitonghop.data.TipData;
import com.haitonghop.modules.cabvn.CabVnActivity;
import com.haitonghop.modules.girl.GirlActivity;
import com.haitonghop.modules.girl.GirlCollectionActivity;
import com.haitonghop.modules.girl.GirlVideoActivity;
import com.haitonghop.modules.haivl.HaiVLActivity;
import com.haitonghop.modules.local.MoreActivity;
import com.haitonghop.modules.local.SettingActivity;
import com.haitonghop.modules.local.UtilsWebActivity;
import com.haitonghop.modules.news.NewsRssActivity;
import com.haitonghop.modules.ohvui.OhVuiActivity;
import com.haitonghop.modules.tamdiem.TamDiemActivity;
import com.haitonghop.modules.truyentranh.TruyenTranhBookmarkActivity;
import com.haitonghop.modules.truyentranh.TruyenTranhCategoryActivity;
import com.haitonghop.network.APIRequestWorker;
import com.haitonghop.network.Request;
import com.haitonghop.network.RequestBackgroundWorker;
import com.haitonghop.network.RequestListener;
import com.haitonghop.requester.UpdateRequester;
import com.haitonghop.utils.AppSettingParams;
import com.haitonghop.utils.FaceBookUtils;
import com.haitonghop.utils.GlobalData;
import com.haitonghop.utils.Logger;

public class MainMenuHaiBLActivity extends Activity implements OnClickListener {

	public static final String APP_ID = "354042864672977";// "157111564357680";

	private LoginButton mLoginButton;
	private Handler mHandler;
	final static int AUTHORIZE_ACTIVITY_RESULT_CODE = 0;
	final static int PICK_EXISTING_PHOTO_RESULT_CODE = 1;
	ProgressDialog dialog;
	String[] permissions = { "offline_access", "publish_stream", "user_photos", "publish_actions", "publish_checkins", "photo_upload" };
	private ImageView userAvatar;
	private TextView userDisplayName;
	private FrameLayout userInfoLayout;
	private Button logoutButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Logger.logMe("onCreateonCreateonCreateonCreate");
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		// Remove notification bar
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.act_mainmenu);

		AppSettingParams.SCREEN_WIDTH = getWindowManager().getDefaultDisplay().getWidth();
		AppSettingParams.SCREEN_HEIGHT = getWindowManager().getDefaultDisplay().getHeight();

		// Create the Facebook Object using the app id.
		Utility.mFacebook = new Facebook(APP_ID);
		// Instantiate the asynrunner object for asynchronous api calls.
		Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook);

		SessionStore.restore(Utility.mFacebook, this);

		FrameLayout layoutHaibl = (FrameLayout) findViewById(R.id.layoutHaiVL);
		FrameLayout layoutFanPage = (FrameLayout) findViewById(R.id.layoutFanPage);
		FrameLayout layoutGirlXinh = (FrameLayout) findViewById(R.id.layoutGirlXinh);
		FrameLayout layoutKhoAnh = (FrameLayout) findViewById(R.id.layoutKhoAnh);
		FrameLayout layoutMeMe = (FrameLayout) findViewById(R.id.layoutMeMe);
		FrameLayout layoutMore = (FrameLayout) findViewById(R.id.layoutMore);
		FrameLayout layoutOhVui = (FrameLayout) findViewById(R.id.layoutOhVui);
		FrameLayout layoutUtil = (FrameLayout) findViewById(R.id.layoutUtil);
		// FrameLayout layoutEpic = (FrameLayout) findViewById(R.id.layoutEpic);
		FrameLayout layoutTruyenTranh = (FrameLayout) findViewById(R.id.layoutTruyenTranh);
		FrameLayout layoutBookmark = (FrameLayout) findViewById(R.id.layoutBookmark);
		FrameLayout layoutNews = (FrameLayout) findViewById(R.id.layoutNews);
		FrameLayout layoutVideoGirlXinh = (FrameLayout) findViewById(R.id.layoutVideoGirlXinh);
		FrameLayout layoutHangTuyen = (FrameLayout) findViewById(R.id.layoutHangTuyen);
		ImageButton setting = (ImageButton) findViewById(R.id.menu_button_right);
		ImageButton menuLeft = (ImageButton) findViewById(R.id.menu_button_left);

		setting.setOnClickListener(this);
		layoutHaibl.setOnClickListener(this);
		layoutFanPage.setOnClickListener(this);
		layoutGirlXinh.setOnClickListener(this);
		layoutKhoAnh.setOnClickListener(this);
		layoutMeMe.setOnClickListener(this);
		layoutMore.setOnClickListener(this);
		layoutOhVui.setOnClickListener(this);
		layoutUtil.setOnClickListener(this);
		// layoutEpic.setOnClickListener(this);
		layoutTruyenTranh.setOnClickListener(this);
		layoutBookmark.setOnClickListener(this);
		layoutNews.setOnClickListener(this);
		layoutVideoGirlXinh.setOnClickListener(this);
		layoutHangTuyen.setOnClickListener(this);
		menuLeft.setOnClickListener(this);

		mHandler = new Handler();
		mLoginButton = (LoginButton) findViewById(R.id.btnConnectFacebook);
		userAvatar = (ImageView) findViewById(R.id.userAvatar);
		userDisplayName = (TextView) findViewById(R.id.userDisplayName);
		userInfoLayout = (FrameLayout) findViewById(R.id.userInfo);
		logoutButton = (Button) findViewById(R.id.btnLogout);

		logoutButton.setOnClickListener(doLogout);
		// restore session if one exists

		SessionEvents.addAuthListener(new FbAPIsAuthListener());
		SessionEvents.addLogoutListener(new FbAPIsLogoutListener());
		/*
		 * Source Tag: login_tag
		 */
		mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions);

		if (Utility.mFacebook.isSessionValid()) {
			requestUserData();
		}

		try {

			String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
			AQUtility.setCacheDir(new File(extStorageDirectory, "Haibua/cache"));

			// set the max number of concurrent network connections, default is
			// 4
			AjaxCallback.setNetworkLimit(4);
			BitmapAjaxCallback.setTimeout(30000);

			// set the max number of images (image width > 50) to be cached in
			// memory, default is 20
			BitmapAjaxCallback.setCacheLimit(20);

			// set the max size of an image to be cached in memory, default is
			// 3600
			// pixels (ie. 600x600)
			BitmapAjaxCallback.setPixelLimit(1280 * 1280);

			// set the max size of the memory cache, default is 1M pixels (4MB)
			// BitmapAjaxCallback.setMaxPixelLimit(3000000);
			// fix me
			ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
			int available = activityManager.getMemoryClass() * 1000000;
			BitmapAjaxCallback.setMaxPixelLimit(available / 4 * 40 / 100);

			new Thread(new Runnable() {
				@Override
				public void run() {
					initOptAQuery();
					initGlobalData();
				}
			}).start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void initOptAQuery() {
		try {
			if (GlobalData.mAQ == null)
				GlobalData.mAQ = new AQuery(getApplicationContext());

			if (GlobalData.opt_avatar == null) {
				GlobalData.opt_avatar = new ImageOptions();
				GlobalData.opt_avatar.round = 10;
				GlobalData.opt_avatar.memCache = true;
				GlobalData.opt_avatar.fileCache = true;
				GlobalData.opt_avatar.preset = BitmapFactory.decodeResource(getResources(), R.drawable.no_preview);
				GlobalData.opt_avatar.fallback = R.drawable.no_preview;
				GlobalData.opt_avatar.animation = AQuery.FADE_IN_FILE;
			}

			if (GlobalData.opt_image == null) {
				GlobalData.opt_image = new ImageOptions();
				GlobalData.opt_image.memCache = true;
				GlobalData.opt_image.fileCache = true;
				GlobalData.opt_image.preset = BitmapFactory.decodeResource(getResources(), R.drawable.no_preview);
				GlobalData.opt_image.fallback = R.drawable.no_preview;
				GlobalData.opt_image.animation = AQuery.FADE_IN_FILE;
			}

			if (GlobalData.opt_gallery_full == null) {
				GlobalData.opt_gallery_full = new ImageOptions();
				GlobalData.opt_gallery_full.memCache = true;
				GlobalData.opt_gallery_full.fileCache = true;
				GlobalData.opt_gallery_full.targetWidth = 400;
				GlobalData.opt_gallery_full.preset = null;
				// GlobalData.opt_gallery_full.fallback =
				// R.drawable.ic_gallery_holder;
				GlobalData.opt_gallery_full.animation = AQuery.FADE_IN_NETWORK;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void initGlobalData() {
		try {
			startWorker();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void startWorker() {
		RequestBackgroundWorker.startWaitingForRequest();
	}

	public static void cleanAllCache() {
		try {
			BitmapAjaxCallback.clearCache();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	OnClickListener doLogout = new OnClickListener() {

		@Override
		public void onClick(View v) {

			DisplayUtils.openConfirmDialog("Đăng xuất", "Bạn muốn đăng xuất tài khoản Facebook?", MainMenuHaiBLActivity.this, new DialogInterface.OnClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which) {

					if (Utility.mFacebook != null) {
						try {
							mLoginButton.doLogout();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
			}, null);

		}
	};

	public void setInfoAndVisibleLayout(String avatar, String userName) {
		if (avatar != null && userName != null) {
			userInfoLayout.setVisibility(View.VISIBLE);
			userDisplayName.setText(userName);
			Logger.logMe("avatar = " + avatar);

			GlobalData.mAQ.id(userAvatar).image(avatar, true, true, 50, 0, new BitmapAjaxCallback() {
				@Override
				public void callback(String url, ImageView imageview, Bitmap bm, AjaxStatus status) {
					if (bm != null) {
						if (userAvatar != null) {
							userAvatar.setImageBitmap(bm);
							userAvatar.setVisibility(View.VISIBLE);
						}
					}
				}
			});
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		if (Utility.mFacebook != null) {
			SessionStore.restore(Utility.mFacebook, this);
			if (!Utility.mFacebook.isSessionValid()) {
				System.out.println("You are logged out!");
			} else {
				Utility.mFacebook.extendAccessTokenIfNeeded(this, null);
			}
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		System.out.println("onActivityResultonActivityResultonActivityResult");
		switch (requestCode) {
		/*
		 * if this is the activity result from authorization flow, do a call
		 * back to authorizeCallback Source Tag: login_tag
		 */
		case AUTHORIZE_ACTIVITY_RESULT_CODE: {
			Utility.mFacebook.authorizeCallback(requestCode, resultCode, data);

			FaceBookUtils.doShareApplication(MainMenuHaiBLActivity.this);
			break;
		}
		/*
		 * if this is the result for a photo picker from the gallery, upload the
		 * image after scaling it. You can use the Utility.scaleImage() function
		 * for scaling
		 */
		case PICK_EXISTING_PHOTO_RESULT_CODE: {
			if (resultCode == Activity.RESULT_OK) {
				Uri photoUri = data.getData();
				if (photoUri != null) {
					Bundle params = new Bundle();
					try {
						params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), photoUri));
					} catch (IOException e) {
						e.printStackTrace();
					}
					params.putString("caption", "FbAPIs Sample App photo upload");
					Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
				} else {
					Toast.makeText(getApplicationContext(), "Error selecting image from the gallery.", Toast.LENGTH_SHORT).show();
				}
			} else {
				Toast.makeText(getApplicationContext(), "No image selected for upload.", Toast.LENGTH_SHORT).show();
			}
			break;
		}
		}
	}

	/*
	 * callback for the apprequests dialog which sends an app request to user's
	 * friends.
	 */
	public class AppRequestsListener extends BaseDialogListener {

		@Override
		public void onComplete(Bundle values) {
			Toast toast = Toast.makeText(getApplicationContext(), "App request sent", Toast.LENGTH_SHORT);
			toast.show();
		}

		@Override
		public void onFacebookError(FacebookError error) {
			Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onCancel() {
			Toast toast = Toast.makeText(getApplicationContext(), "App request cancelled", Toast.LENGTH_SHORT);
			toast.show();
		}
	}

	/*
	 * callback after friends are fetched via me/friends or fql query.
	 */
	public class FriendsRequestListener extends BaseRequestListener {

		@Override
		public void onComplete(final String response, final Object state) {
			dialog.dismiss();
			System.out.println("FriendsRequestListener onComplete");
			// Intent myIntent = new Intent(getApplicationContext(),
			// FriendsList.class);
			// myIntent.putExtra("API_RESPONSE", response);
			// myIntent.putExtra("METHOD", graph_or_fql);
			// startActivity(myIntent);
		}

		public void onFacebookError(FacebookError error) {
			dialog.dismiss();
			Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
		}
	}

	/*
	 * callback for the photo upload
	 */
	public class PhotoUploadListener extends BaseRequestListener {

		@Override
		public void onComplete(final String response, final Object state) {
			dialog.dismiss();

			Toast toast = Toast.makeText(getApplicationContext(), "Upload Photo executed", Toast.LENGTH_SHORT);
			toast.show();
			// mHandler.post(new Runnable() {
			//
			// public void run() {
			// new UploadPhotoResultDialog(HaiVLActivity.this,
			// "Upload Photo executed", response).show();
			// }
			// });
		}

		public void onFacebookError(FacebookError error) {
			dialog.dismiss();
			Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
		}
	}

	public class FQLRequestListener extends BaseRequestListener {

		@Override
		public void onComplete(final String response, final Object state) {
			mHandler.post(new Runnable() {

				@Override
				public void run() {
					Toast.makeText(getApplicationContext(), "Response: " + response, Toast.LENGTH_LONG).show();
				}
			});
		}

		public void onFacebookError(FacebookError error) {
			Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
		}
	}

	/*
	 * Callback for fetching current user's name, picture, uid.
	 */
	public class UserRequestListener extends BaseRequestListener {

		@Override
		public void onComplete(final String response, final Object state) {
			JSONObject jsonObject;
			try {
				jsonObject = new JSONObject(response);

				final String picURL = jsonObject.getJSONObject("picture").getJSONObject("data").getString("url");
				final String name = jsonObject.getString("name");
				Utility.userUID = jsonObject.getString("id");
				AppSettingParams.userDisplayName = name;
				AppSettingParams.userAvatar = picURL;

				AppSettingParams.save(MainMenuHaiBLActivity.this);

				mHandler.post(new Runnable() {

					@Override
					public void run() {
						setInfoAndVisibleLayout(picURL, name);
					}
				});

			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

	}

	/*
	 * The Callback for notifying the application when authorization succeeds or
	 * fails.
	 */

	public class FbAPIsAuthListener implements AuthListener {

		@Override
		public void onAuthSucceed() {
			requestUserData();
		}

		@Override
		public void onAuthFail(String error) {
			System.out.println("onAuthFail = ");
		}
	}

	/*
	 * The Callback for notifying the application when log out starts and
	 * finishes.
	 */
	public class FbAPIsLogoutListener implements LogoutListener {

		@Override
		public void onLogoutBegin() {
			Toast.makeText(getApplicationContext(), "Đăng xuất tài khoản...", Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onLogoutFinish() {
			Toast.makeText(getApplicationContext(), "Đăng xuất thành công...", Toast.LENGTH_LONG).show();
			mLoginButton.setVisibility(View.VISIBLE);
			userInfoLayout.setVisibility(View.GONE);
			AppSettingParams.userDisplayName = "";
			AppSettingParams.userAvatar = "";
			userDisplayName.setText("");
			Utility.mFacebook.setAccessToken(null);
			SessionStore.clear(MainMenuHaiBLActivity.this);
		}
	}

	public void requestUserData() {
		mLoginButton.setVisibility(View.GONE);

		if (AppSettingParams.userDisplayName.equals("")) {
			Toast.makeText(getApplicationContext(), "Đang lấy thông tin của bạn...", Toast.LENGTH_LONG).show();

			SessionStore.save(Utility.mFacebook, MainMenuHaiBLActivity.this);

			// mText.setText("Fetching user name, profile pic...");
			Bundle params = new Bundle();
			params.putString("fields", "name, picture");
			Utility.mAsyncRunner.request("me", params, new UserRequestListener());
		} else {
			mHandler.post(new Runnable() {

				@Override
				public void run() {
					setInfoAndVisibleLayout(AppSettingParams.userAvatar, AppSettingParams.userDisplayName);
				}
			});
		}
	}

	@Override
	protected void onStart() {
		APIRequestWorker.getInstance().clearAllRequests();

		RequestBackgroundWorker.startWaitingForRequest();

		if (!AdsViewControl.NO_ADS) {
			AppSettingParams.initPublishId(MainMenuHaiBLActivity.this);
			doCallUpdatesVersion();
		}
		AppSettingParams.initSession(this);
		AppSettingParams.initFaceBookAppId(MainMenuHaiBLActivity.this);

		super.onStart();
	};

	@Override
	public void onClick(View v) {
		Intent intent = null;
		if (v != null) {
			int id = v.getId();
			switch (id) {
			case R.id.menu_button_left:
				Intent intent1 = new Intent(getApplication(), GreatAppActivity.class);
				startActivity(intent1);
				break;
			case R.id.menu_button_right:
				Intent intent2 = new Intent(getApplication(), SettingActivity.class);
				startActivity(intent2);
				break;
			case R.id.layoutHaiVL:
				doShow(HaiBLModule.HAIVL);
				break;
			case R.id.layoutFanPage:
				String url = "https://www.facebook.com/pages/H%C3%A0i-b%E1%BB%B1a-Community/427416300681862";
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
				startActivity(browserIntent);
				break;
			case R.id.layoutGirlXinh:
				doShow(HaiBLModule.GIRLXINH);
				break;
			case R.id.layoutKhoAnh:
				doShow(HaiBLModule.TAMDIEM);
				break;
			case R.id.layoutMeMe:
				doShow(HaiBLModule.CABVN);
				break;
			case R.id.layoutMore:
				doShow("more");
				break;
			case R.id.layoutTruyenTranh:
				doShow(HaiBLModule.COMIC);
				break;
			case R.id.layoutOhVui:
				doShow(HaiBLModule.OHVUI);
				break;
			case R.id.layoutBookmark:
				doShow(HaiBLModule.BOOKMARK);
				break;
			case R.id.layoutNews:
				doShow(HaiBLModule.QUAYBAO);
				break;
			// case R.id.layoutEpic:
			// intent = new Intent(getApplication(), EpicVnActivity.class);
			// startActivity(intent);
			// break;
			case R.id.layoutUtil:
				intent = new Intent(getApplication(), UtilsWebActivity.class);
				startActivity(intent);
				break;
			case R.id.layoutVideoGirlXinh:
				intent = new Intent(getApplication(), GirlVideoActivity.class);
				startActivity(intent);
				break;
			case R.id.layoutHangTuyen:
				intent = new Intent(getApplication(), GirlCollectionActivity.class);
				startActivity(intent);
				break;
			default:
				break;
			}
		}
	}

	public static boolean isCall = false;

	void doCallUpdatesVersion() {
		if (isCall)
			return;
		isCall = true;
		UpdateRequester updateRequester = new UpdateRequester(new RequestListener() {

			@Override
			public void onRequestFailed(String errorMsg, Request request) {

			}

			@Override
			public void onRequestComplete(Request request) {
				if (request instanceof UpdateRequester) {
					final UpdateRequester r = (UpdateRequester) request;
					if (r.getVersion() > AppSettingParams.VERSION_CODE) {
						final String message = r.getMessage();
						final String title = "Cập nhật" + (r.isForce() ? " bắt buộc" : "");
						final String link = r.getLink();
						// has new updates for app

						final AlertDialog.Builder alert = DisplayUtils.showUpdatesDialog(r.isForce(), title, message, MainMenuHaiBLActivity.this, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								finish();

								Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
								startActivity(browserIntent);
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								if (r.isForce()) {
									finish();
								}
							}
						}, null);

						runOnUiThread(new Runnable() {
							@Override
							public void run() {
								try {
									alert.show();
								} catch (Exception e) {
									e.printStackTrace();
								}
							}
						});
					} else {
						System.out.println("show tip");
						// show tip len
						final TipData data = r.getTipdata();
						if (data != null) {
							System.out.println("show tip");
							runOnUiThread(new Runnable() {
								@Override
								public void run() {
									DisplayUtils.openTipDialog("Chú ý", data.getMesage(), data.getLink(), MainMenuHaiBLActivity.this);
								}
							});

						}
					}
				}

			}
		});

		APIRequestWorker.getInstance().addAPIRequest(updateRequester);
	}

	public void doShow(String id) {
		Log.d("doShow", "" + id);
		if (id != null) {
			if (HaiBLModule.HAIVL.equals(id)) {
				Intent intent = new Intent(getApplication(), HaiVLActivity.class);
				startActivity(intent);
			} else if (HaiBLModule.CABVN.equals(id)) {
				Intent intent = new Intent(getApplication(), CabVnActivity.class);
				startActivity(intent);
			} else if (HaiBLModule.OHVUI.equals(id)) {
				Intent intent = new Intent(getApplication(), OhVuiActivity.class);
				startActivity(intent);
			} else if (HaiBLModule.TAMDIEM.equals(id)) {
				Intent intent = new Intent(getApplication(), TamDiemActivity.class);
				startActivity(intent);
			} else if (HaiBLModule.QUAYBAO.equals(id)) {
				Intent intent = new Intent(getApplication(), NewsRssActivity.class);
				startActivity(intent);
			} else if (HaiBLModule.GIRLXINH.equals(id)) {
				Intent intent = new Intent(getApplication(), GirlActivity.class);
				startActivity(intent);
			} else if (HaiBLModule.COMIC.equals(id)) {
				Intent intent = new Intent(getApplication(), TruyenTranhCategoryActivity.class);
				startActivity(intent);
			} else if (HaiBLModule.BOOKMARK.equals(id)) {
				Intent intent = new Intent(getApplication(), TruyenTranhBookmarkActivity.class);
				startActivity(intent);
			} else {
				Logger.logMe(">>>>>> id - " + id);
				Intent intent = new Intent(getApplication(), MoreActivity.class);
				startActivity(intent);
			}
		}
	}

}
